﻿using System.Collections.ObjectModel;
using TestBat.IModels.Models;
using TestBat.IViewModels.Base;
using TestBat.IViewModels.Factories;
using TestBat.IViewModels.Workspaces.Trainees;

namespace TestBat.ViewModels.Workspaces.Trainees
{
    public class TraineeGroupListViewModel : ListViewModel<ITraineeGroupViewModel, ObservableCollection<ITraineeGroupViewModel>>, ITraineeGroupListViewModel
    {
        public TraineeGroupListViewModel(ITraineeGroupModel traineeGroupModel, ITraineeGroupViewModelFactory traineeGroupViewModelFactory, bool checkUnsavedChanges)
            : base(checkUnsavedChanges)
        {
            this.traineeGroupModel = traineeGroupModel;
            this.traineeGroupViewModelFactory = traineeGroupViewModelFactory;
        }

        protected override ObservableCollection<ITraineeGroupViewModel> _RecreateItems()
        {
            ObservableCollection<ITraineeGroupViewModel> list = new ObservableCollection<ITraineeGroupViewModel>();
            foreach (var traineeGroup in traineeGroupModel.GetAll())
            {
                ITraineeGroupViewModel traineeGroupViewModel = traineeGroupViewModelFactory.Create(traineeGroup);
                list.Add(traineeGroupViewModel);
            }

            return list;
        }

        //[CheckUnsavedChanges]
        //protected override void ChangeSelected(ITraineeGroupViewModel from, ITraineeGroupViewModel to)
        //{
        //    base.ChangeSelected(from, to);
        //}

        private readonly ITraineeGroupModel traineeGroupModel;

        private readonly ITraineeGroupViewModelFactory traineeGroupViewModelFactory;
    }
}
